﻿using OnlineMealOrdering.Domain.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineMealOrdering.Domain
{
    public class CouponEntity : AuditableEntity
    {
        public string Code { get; set; }

        public EnumCouponType CouponType { get; set; }

        public EnumCouponStatus Status { get; set; }

        public decimal Value { get; set; }

        public DateTime OverdueTime { get; set; }

        public void UpdateCouponEnable(int id,bool enable=false)
        {
            if (enable)
                Status = EnumCouponStatus.Enable;
            else
                Status = EnumCouponStatus.Cancle;
        }

        public static CouponEntity Create(EnumCouponType type, int addDay, decimal val = 0)
        {
            var entity = new CouponEntity();
            entity.Code = Guid.NewGuid().ToString().Replace("-", "");
            entity.Status = EnumCouponStatus.Create;
            entity.CouponType = type;
            entity.OverdueTime = DateTime.Now.AddDays(addDay);
            if (type == EnumCouponType.Cash)
            {
                entity.Value = val;
            }
            else if (type == EnumCouponType.Discount)
            {
                entity.Value = val;
            }

            return entity;
        }
        /// <summary>
        /// 批量创建
        /// </summary>
        /// <param name="type"></param>
        /// <param name="val"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static ICollection<CouponEntity> BatchCreate(EnumCouponType type, int addDay, decimal val = 0, int amount = 0)
        {
            ICollection<CouponEntity> coupons = new List<CouponEntity>();
            for (int i = 0; i < amount; i++)
            {
                coupons.Add(CouponEntity.Create(type,addDay,val));
            }

            return coupons;
        }
    }
}
